package com.zb.jsp.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import com.zb.jsp.common.HibernateSessionFactory;
import com.zb.jsp.vo.commonVo.AdvertAddressNameVo;
import com.zb.jsp.vo.commonVo.AdvertTypeVo;

/**	
 * 用来定义一些共同 的dao方法
 * @author Administrator
 *
 */
public class CommonDao {

	Session session = null;
	Transaction transaction = null;
	
	public List<AdvertTypeVo> fidAdvertTypeList() {
		List<AdvertTypeVo> advertTypeVoList = null;
		
		try {
			// 1.创建 Session链接
			session = HibernateSessionFactory.getSession();
			
			//用来查询广告类型的hql文
			String hql = "select new com.zb.jsp.vo.commonVo.AdvertTypeVo(code,value) from TblDefType";
			// 2.获得一个查询的query
			Query hqlQuery = session.createQuery(hql);
			// 3.执行查询动作
			advertTypeVoList = hqlQuery.list();

		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			// 4.关闭session
			HibernateSessionFactory.closeSession();
		}
		
		return advertTypeVoList;	
	}
	
	/**	
	 * 查询广告所属的广告位名称
	 * @return advertAddressNameVoList 广告所属的广告位id和name
	 */
	public List<AdvertAddressNameVo> findAdvertAddressNameList() {
		
		List<AdvertAddressNameVo> advertAddressNameVoList = null;
		
		try {
			// 1.创建 Session链接
			session = HibernateSessionFactory.getSession();
			
			//用来查询广告类型的hql文
			String hql = "select new com.zb.jsp.vo.commonVo.AdvertAddressNameVo(id,advertName) from TblAdvertAddress";
			// 2.获得一个查询的query
			Query hqlQuery = session.createQuery(hql);
			// 3.执行查询动作
			advertAddressNameVoList = hqlQuery.list();

		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			// 4.关闭session
			HibernateSessionFactory.closeSession();
		}
		
		return advertAddressNameVoList;	
	}
	
}
